<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<form method="post" action="" id="listform">
  <div class="panel admin-panel">
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">

      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
          <th width="100" style="text-align:left; padding-left:20px;">主键ID</th>
          <th width="10%">课程id</th>
          <th>老师工号</th>
          <th>学院</th>
          <th>限选年级</th>
          <th>时间</th>
          <th>小节</th>
          <th>地点</th>
          <th>最大人数</th>
          <th>最小人数</th>
          <th>当前人数</th>
          <th>备注</th>
          <th width="310">操作</th>
      </tr>
        <tbody class="student-list">

        </tbody>
      <volist name="list" id="vo">
		<tr>
			<td colspan="8">
				<div class="pagelist">
					<a href="">上一页</a>
					<span class="current">1</span>
					<a href="">2</a>
					<a href="">3</a>
					<a href="">下一页</a>
					<a href="">尾页</a>
				</div>
			</td>
		 </tr>
    </table>
  </div>
</form>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        var tn=1;
        $.ajax({
            type:"POST",
            url:"/workview/elcourall",
            datatype:'json',
            success:function(data){
                if(data.status==401){
                    alert("熔断开启，系统异常");
                    window.location.href="login.html";
                    return;
                }
                var  lists = data.data;
                console.log(data);
                for (var i = 0; i < lists.length; i++){
                    var cid = "${lists[i].course_id}";
                    var html = "";
                    <!--sno password name college_name grade class_name remark-->
                    html +=`
                        <tr>
                        <td style='text-align:left; padding-left:20px;'>${lists[i].elective_course_id}</td>"+
                        <td class="cc" name="cc" class="cc">${lists[i].course_id} </td>
                        <td>${lists[i].tno}</td>
                        <td>${lists[i].college_name}</td>
                        <td>${lists[i].restricted_grade}</td>
                        <td>${lists[i].time}</td>
                        <td>${lists[i].know}</td>
                        <td>${lists[i].place}</td>
                        <td>${lists[i].max_number}</td>
                        <td>${lists[i].min_number}</td>
                        <td>${lists[i].current_number}</td>
                        <td>${lists[i].remark}</td>
                             <td>
                                <div class="button-group">
                                    <a onclick="check1('${lists[i].elective_course_id}','${lists[i].restricted_grade}')" class="button border-main" ><span class="icon-edit"></span> 选课</a>
                                    <a onclick="check2('${lists[i].course_id}')" class="button border-main" ><span class="icon-edit"></span> 查看课程详情</a>
                                </div>
                             </td>
                         </tr>
                        `

                    $('.student-list').append(html);
                    // $.ajax({
                    //         type:"POST",
                    //         url:"/workview/course_libraryIdlist",
                    //         datatype:'json',
                    //         async:false,
                    //         data:({
                    //             course_id: cid
                    //         }),
                    //         success:function(e){
                    //             if(e.status==401){
                    //                 alert("熔断开启，系统异常");
                    //                 window.location.href="login.html";
                    //                 return;
                    //             }
                    //             var  lists = e.e;
                    //             console.log(data);
                    //             for (var i = 0; i < lists.length; i++){
                    //                 var html = "";
                    //                 html +=`${lists[i].course_name}`
                    //                 $('.cc').append(html);
                    //             }
                    //         }
                    //     })
                }
            }
        })
    })
     function check1(sn,S){
         var sno = localStorage.getItem("studentsno");
         var student_name = localStorage.getItem("studentname");
         var studentgrade = localStorage.getItem("studentgrade");
         var remark = "";
         if(S!=studentgrade)
         {
             alert("限制选择年级请选择符合规定的年级")
             return;
         }
         if(S==studentgrade)
         {
             $.ajax({
                 type:"POST",
                 dataType:"json",
                 url:"/workview1/sxadd",
                 data:({
                     elective_course_id:sn,
                     student_name: student_name,
                     sno:sno,
                     remark: remark
                 }),
                 success:function(data){
                     console.log(data);
                     if(data.status==401){
                         alert("熔断开启，系统异常");
                         window.location.href="login.html";
                         return;
                     }
                     if(data.status==200) {
                         alert("成功")
                         window.location.href="stelective_courselist.html";
                         return;
                     }
                     if(data.status==2000) {
                         alert(data.msg)
                         window.location.href="stelective_courselist.html";
                         return;
                     }
                     if(data.status==500) {
                         alert("失败");
                         window.location.href="stelective_courselist.html";
                         return;
                     }
                     if(data.status==null) {
                         alert("异常");
                         window.location.href="stelective_courselist.html";
                         return;
                     }
                 },
                 error:function(XMLHttpRequest,textStatus) {
                     if (textStatus === 'timeout') {
                         alert('請求超時');
                         setTimeout(function () {
                             alert('重新请求');
                         }, 2000);
                     }
                     window.location.href="stelective_courselist.html";
                 }

             });
         }
         // var remake = null;
         // $.ajax({
         //     type:"POST",
         //     dataType:"json",
         //     url:"/workview1/sxadd",
         //     data:({
         //         sno: sno,
         //         elective_course_id:sn,
         //         student_name: student_name,
         //         remark:remake
         //     }),
         //     success:function(data){
         //         console.log(data);
         //         if(data.status==401){
         //             alert("熔断开启，系统异常");
         //             window.location.href="login.html";
         //             return;
         //         }
         //         if(data.status==200) {
         //             alert("成功")
         //             window.location.href="stelective_courselist.html";
         //             return;
         //         }
         //         if(data.status==500) {
         //             alert("失败");
         //             window.location.href="stelective_courselist.html";
         //             return;
         //         }
         //         if(data.status==null) {
         //             alert("异常");
         //             window.location.href="stelective_courselist.html";
         //             return;
         //         }
         //     },
         //     error:function(XMLHttpRequest,textStatus) {
         //         if (textStatus === 'timeout') {
         //             alert('請求超時');
         //             setTimeout(function () {
         //                 alert('重新请求');
         //             }, 2000);
         //         }
         //         window.location.href="stelective_courselist.html";
         //     }
         //
         // });

    }

function check2(sn){
    localStorage.setItem("course_id1",sn);
    window.location.href="stcourse_librarylist.html";

}

//全选
$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

//批量删除
function DelSelect(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;		
		$("#listform").submit();		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

//批量排序
function sorts(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){	
		
		$("#listform").submit();		
	}
	else{
		alert("请选择要操作的内容!");
		return false;
	}
}


//批量首页显示
function changeishome(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");		
	
		return false;
	}
}

//批量推荐
function changeisvouch(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");	
		
		return false;
	}
}

//批量置顶
function changeistop(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){		
		
		$("#listform").submit();	
	}
	else{
		alert("请选择要操作的内容!");		
	
		return false;
	}
}


//批量移动
function changecate(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){		
		
		$("#listform").submit();		
	}
	else{
		alert("请选择要操作的内容!");
		
		return false;
	}
}

//批量复制
function changecopy(o){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){	
		var i = 0;
	    $("input[name='id[]']").each(function(){
	  		if (this.checked==true) {
				i++;
			}		
	    });
		if(i>1){ 
	    	alert("只能选择一条信息!");
			$(o).find("option:first").prop("selected","selected");
		}else{
		
			$("#listform").submit();		
		}	
	}
	else{
		alert("请选择要复制的内容!");
		$(o).find("option:first").prop("selected","selected");
		return false;
	}
}

</script>
</body>
</html>